//==============================================================================
#include "Stringify.h"

//==============================================================================
std::string Stringify(int x) {
    std::ostringstream o;

    o << x;

    return o.str();
}

//------------------------------------------------------------------------------
std::string cStringify(char* x) {
    std::string o = x;

    return o;
}

//------------------------------------------------------------------------------
std::string fStringify(float x) {
    std::ostringstream o;

    o << x;

    return o.str();
}

//------------------------------------------------------------------------------
std::string dStringify(float x) {
    std::ostringstream o;

    o << x;

    return o.str();
}

//------------------------------------------------------------------------------
std::string StringifyPack(Uint32 X) {
    std::string Content = "";

    Content += (char)((X >> 24) & 0xFF);
    Content += (char)((X >> 16) & 0xFF);
    Content += (char)((X >> 8)  & 0xFF);
    Content += (char)((X >> 0)  & 0xFF);

    printf("%x %x %x %x\n", Content[0], Content[1], Content[2], Content[3]);

    return Content;
}

//------------------------------------------------------------------------------
Uint32 StringifyUnpack(std::string Content, int Pos) {
    Content = Content.substr(Pos, 4);

    printf("%x %x %x %x\n", Content[0], Content[1], Content[2], Content[3]);

    Uint32 X = ((Content[3] << 24) | (Content[2] << 16) | (Content[1] << 8) | (Content[0] << 0));

    return X;
}

//==============================================================================
//http://www.infernodevelopment.com/perfect-c-string-explode-split
std::vector<std::string> StringifyExplode(std::string str, std::string separator) {
    std::vector<std::string> Results;

    int found;
    found = str.find_first_of(separator);
    while(found != std::string::npos){
        if(found > 0){
            Results.push_back(str.substr(0,found));
        }

        str = str.substr(found+1);
        found = str.find_first_of(separator);
    }

    if(str.length() > 0){
        Results.push_back(str);
    }

    return Results;
}

//==============================================================================
